package org.watchrecords.elements;

import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.panel.Panel;
import org.watchrecords.WatchRecordsSession;
import org.watchrecords.dbo.User;
import org.watchrecords.pages.MainPage;

public class LoginPanel extends Panel {
    /**
     * 
     */
    private static final long serialVersionUID = 5142142789461636289L;

    public LoginPanel(String id, User user) {
        super(id);
        
        add(new Label("username", user == null ? "" : user.getName()));
        add(new Link<Object>("logoutLink") {
            private static final long serialVersionUID = 6960290179497842726L;

            @Override
            public void onClick() {
                ((WatchRecordsSession) getSession()).signOut();
                setResponsePage(MainPage.class);
                setRedirect(true);
            }
        });
    }
}
